//
//  LJButtonPressAnimationController.m
//  LJAnimationsDemo
//
//  Created by raymond on 17/1/9.
//  Copyright © 2017年 raymond. All rights reserved.
//

#import "LJButtonPressAnimationController.h"
#import "LJPressScaleButton.h"

@interface LJButtonPressAnimationController ()

@property (nonatomic, strong) UIImageView *normalImageView;
@property (nonatomic, strong) UIImageView *blurImageView;
@property (nonatomic, strong) LJPressScaleButton *pressBtn;

@property (nonatomic, strong) CAShapeLayer *circleShape1;
@property (nonatomic, strong) CAShapeLayer *circleShape2;

@end

@implementation LJButtonPressAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupSubviews];
    
    [self setupNormarlBackItem];

}

- (void)setupSubviews {
    [self.backgroundView addSubview:self.normalImageView];
    [self.backgroundView addSubview:self.blurImageView];
    [self.contentView addSubview:self.pressBtn];
    [self.contentView.layer addSublayer:self.circleShape1];
    [self.contentView.layer addSublayer:self.circleShape2];
}

#pragma mark - getter

- (UIImageView *)normalImageView {
    if (!_normalImageView) {
        _normalImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _normalImageView.contentMode = UIViewContentModeScaleAspectFill;
        _normalImageView.image = [UIImage imageNamed:@"1"];
    }
    return _normalImageView;
}

- (UIImageView *)blurImageView {
    if (!_blurImageView) {
        _blurImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _blurImageView.contentMode = UIViewContentModeScaleAspectFill;
        _blurImageView.image = [self.normalImageView.image blurImage];
    }
    return _blurImageView;
}

- (LJPressScaleButton *)pressBtn {
    if (!_pressBtn) {
        _pressBtn = [[LJPressScaleButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _pressBtn.center = CGPointMake(self.contentView.width * 0.5, self.contentView.height * 0.5);
    }
    return _pressBtn;
}

- (CAShapeLayer *)circleShape1 {
    if (!_circleShape1) {
        _circleShape1 = [CAShapeLayer layer];
        
        CGFloat radius = 50;
        _circleShape1.lineWidth = 0.5f;
        _circleShape1.bounds   =
                CGRectMake(0, 0, (_circleShape1.lineWidth + radius) * 2, (_circleShape1.lineWidth + radius) * 2);
        _circleShape1.position = CGPointMake(self.contentView.width * 0.5, self.contentView.height * 0.5);
        _circleShape1.strokeColor = [UIColor whiteColor].CGColor;
        _circleShape1.fillColor = [UIColor clearColor].CGColor;
        UIBezierPath *path  = [UIBezierPath bezierPathWithArcCenter:CGPointMake((_circleShape1.lineWidth + radius), (_circleShape1.lineWidth + radius))
                                                             radius:radius + _circleShape1.lineWidth / 2.f
                                                         startAngle:0
                                                           endAngle:M_PI * 2
                                                          clockwise:NO];
        
        _circleShape1.path = path.CGPath;
    }
    return _circleShape1;
}

- (CAShapeLayer *)circleShape2 {
    if (!_circleShape2) {
        _circleShape2 = [CAShapeLayer layer];
        
        CGFloat radius = 52.f;
        _circleShape2.lineWidth = 0.5f;
        _circleShape2.bounds   =
        CGRectMake(0, 0, (_circleShape2.lineWidth + radius) * 2, (_circleShape2.lineWidth + radius) * 2);
        _circleShape2.position = CGPointMake(self.contentView.width * 0.5, self.contentView.height * 0.5);
        _circleShape2.strokeColor = [UIColor whiteColor].CGColor;
        _circleShape2.fillColor = [UIColor clearColor].CGColor;
        UIBezierPath *path  = [UIBezierPath bezierPathWithArcCenter:CGPointMake((_circleShape2.lineWidth + radius), (_circleShape2.lineWidth + radius))
                                                             radius:radius + _circleShape2.lineWidth / 2.f
                                                         startAngle:0
                                                           endAngle:M_PI * 2
                                                          clockwise:YES];
        _circleShape2.path = path.CGPath;
    }
    return _circleShape2;
}

@end
